import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;

public class NGuessNumber {
    int[] answer;
    public int[] generateAnswer(){
        Random random = new Random();
        int[] answers = new int[4];
        answers[0] = random.nextInt(10);
        answers[1] = random.nextInt(10);
        answers[2] = random.nextInt(10);
        answers[3] = random.nextInt(10);
        answer = answers;
        return answers;
    }
    public int[] getPlayerInput(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入猜测的数字");
        int[] result = new int[4];
        result[0] = sc.nextInt();
        result[1] = sc.nextInt();
        result[2] = sc.nextInt();
        result[3] = sc.nextInt();
        return result;
    }
    public  Map<Integer,Boolean> compareGuessAnswer(int[] answer,int[] input){
        Map<Integer,Boolean> result = new HashMap<>();
        for (int i = 0;i<answer.length;i++){
            if (answer[i] == input[i]){
                result.put(answer[i],true);
            }else{
                result.put(answer[i],false);
            }
        }
        return result;
    }
    public boolean isWin( Map<Integer,Boolean> result){
        for (boolean b:
                result.values()) {
            if(b == false){
                return  false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        while (true){
            NGuessNumber game = new NGuessNumber();
            game.generateAnswer();
            System.out.println(game.answer[0]);
            System.out.println(game.answer[1]);
            System.out.println(game.answer[2]);
            System.out.println(game.answer[3]);
            while (true){
                int[] inputresult = game.getPlayerInput();
                Map<Integer,Boolean> compResult = game.compareGuessAnswer(game.answer,inputresult);
                if (game.isWin(compResult)){
                    System.out.println("你胜利了");
                    break;
                }else{
                    for(int i = 0;i<compResult.size();i++){
                        System.out.println("数字 ["+(i+1)+"]"+( (boolean)(compResult.values().toArray()[i])?"正确":"错误"));
                    }
                }
            }
            System.out.println("要再来一局吗? 按1继续");
            if (sc.nextInt() != 1){
                break;
            }
        }
    }

}